#Prepare data
line_df <- gapminder %>%
filter (country %in% c ("Afghanistan" ,"Albania" ,"Algeria" ,"Angola" ,"Argentina" ,"Australia" ,"Austria" ,"Bahrain" ,"Bangladesh" ,"Belgium" ,"Benin" ))
# data
latest_values <- line_df %>%
top_n (1 , year) %>%
mutate_if (is.numeric, round, digits = 0 ) %>%
arrange (desc (lifeExp))
colnames (latest_values) <- c ("Country" , "Continent" , "Year" , "Life Expectancy" , "Poulation" , "GDP Per Capita" )
improvement_formatter <- formatter ("span" ,
style = x ~ style (font.weight = "bold" ,
color = ifelse (x > 8000 , customGreen, ifelse (x < 8000 , customRed, "black" ))),
x ~ icontext (ifelse (x> 8000 , "arrow-up" , "arrow-down" ), x)
)
benchmark <- formatter ("colorbar" , style = x ~ style (display = "block" ,
padding = "0 4px" ,
` border-radius ` = "4px" ,
#width = "40px",
` background-color ` = ifelse (x > 70 ,
customGreen, ifelse (x < 70 , customRed, "black" )),
NA )
)
# Table
latest_values |>
formattable (align = c ("l" ,"c" ,"c" ,"r" ,"r" ,"r" ),
list (` Country ` = formatter (
"span" , style = ~ style (display = "block" ,
padding = "0 4px" , ` border-radius ` = "4px" , color = "white" , ` background-color ` = nhs_palette ("midlands_region" ),font.weight = "bold" )),
` Life Expectancy ` = benchmark,
` GDP Per Capita ` = improvement_formatter
))#, table.attr = 'style="font-size: 20px;";\"')